<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <script src="../js/vue.js"></script>
</head>

<body>
   
    <div id="root">
        <h2>学校名称：{{school.name}}</h2>
        <h2>学校地址：{{school.address}}</h2>
        <h2>校长：{{school.leader}}</h2>
        <br>
        <h1>学生信息</h1>
        <button @click="addSex()">点击添加学生的性别</button>
        <h2>姓名：{{student.name}}</h2>
        <h2 v-if="student.sex">性别:{{student.sex}}</h2>
        <h2>年龄：真实:{{student.age.rAge}}虚假:{{student.age.age}}</h2>
        <h2>朋友</h2>
        <ul>
            <li v-for="(item,index) in student.friend" :key="index">
                {{item.name}}--{{item.age}}
            </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: "#root",
            data: {
                school:{
                    name: "渭南师范",
                    address: "陕西渭南",
                    
                },
                student: {
                    name: "张三",
                    age: {
                        rAge: 30,
                        age: 18
                    },
                    friend: [
                        { name: "李四", age: 20 },
                        {name:"王五",age:19}
                    ]
                }
            },
            methods:{
                addSex(){
                    // Vue.set(this.student,"sex","男");
                    vm.$set(this.student,"sex","女");
                }
            }
        })

    </script>
</body>

</html>